home *** CD-ROM | disk | FTP | other *** search
- #pragma once
-
- ///////////////////////////////////////////////////////////////
- // Hydra classes are Copyright ©1997 by Rainer Brockerhoff.
- //
- // Submitted as part of the paper :
- // "On Having Two (or More) Heads, or : Real-time Programming in Spite of
- // the MacOS", for MacHack 1997
- //
- // This is an example application for illustrating use of the Hydra classes.
- // It seems to run OK on any PowerMac under System 7.5 or later with standard
- // extensions and control panels.
- // It may crash if you open too many windows or have stuff installed which messes
- // with the same system resources that I do. See "Hydra.cp" and "Hydra.h" for
- // the full story.
- // This example uses the least error checking it can get away with.
- //
- // You may use the Hydra classes in your application at no cost;
- // however, the application's "About" box should repeat my
- // copyright line as above. Be sure to write my name correctly ;-)
- // I'd also appreciate getting a demo copy of your application.
- // These classes have not been exhaustively tested in this form
- // and all use is at your own risk.
- //
- // Contact me at <rainer@machome.com.br> or
- // http://www.machome.com.br/delta/
- //
- // Stylistic note :
- // Astute older colleagues will no doubt deduce that in my misspent youth I:
- // 1) learned FORTRAN (short variable names; local variables called i,j,k)
- // 2) learned PL/I (using }; everywhere)
- // 3) used punch cards (using {} even when not needed, to more easily insert
- // printf debug lines)
- // 4) had too little contact with other programmers and so failed to learn
- // proper indentation, naming or bracing standards.
- // They're probably right on all counts... :-)
- //
- // I'm assuming CodeWarrior 12 (or Pro 1) is being used.
- //
- // This source file is overcommented, for pedagogical purposes only.
-
- enum { // these enums define our window types.
- lines,
- rects
- };
-
- ///////////////////////////////////////////////////////////////
- // Our example application class.
- // See HydraExample.cp for details.
- //
- class ExampleApp : public HydraApplication, public LListener {
- public:
- ExampleApp();
- virtual ~ExampleApp();
- virtual Boolean ObeyCommand(CommandT inCommand,void* ioParam);
- virtual void FindCommandStatus(CommandT inCommand,Boolean &outEnabled,Boolean &outUsesMark,Char16 &outMark,Str255 outName);
- protected:
- virtual void Initialize();
- virtual void ListenToMessage(MessageT inMessage,void* ioParam);
- };
-
- ///////////////////////////////////////////////////////////////
- // Our example window class.
- // See HydraExample.cp for details.
- //
- class ExampleWindow : public HydraWindow {
- public:
- enum { class_ID = 'Wind' }; // remember to use this in PowerPlant Constructor
- enum { updatesPerSecond = 10 }; // window update frequency
- ExampleWindow(LStream* inStream);
- virtual ~ExampleWindow();
- static ExampleWindow* CreateWindow(short type,LCommander* inSuperCommander);
- void DoUpdate();
- const static short ;
- protected:
- virtual void FinishCreateSelf();
- virtual void DrawSelf();
- virtual void ClickSelf(const SMouseDownEvent& inMouseDown);
- void DrawLines(short x,short y);
- void DrawRects();
- LSimpleThread* mThread; // local window's update thread
- LGWorld* mGWorld; // local LGWorld to hold the window's image
- Rect mFrame; // window's frame in local coordinates
- short mX,mY; // center point coordinates
- short mState; // state for 'lines' window
- short mIndex; // index for 'lines' window
- short mStep; // step for 'lines' window
- short mHueDelta; // hue delta for 'lines' window
- HSVColor mHSV; // current color
- UInt32 mLastTime; // time of last update
- };
-
- ///////////////////////////////////////////////////////////////
- // Global function prototypes.
- // See HydraExample.cp for details.
- //
- void windowThread(LThread& thread,void* arg);
- long randomInRange(long from,long to);
-
-